<?php
include('./SourceCode/Session.php');
include('./SourceCode/mysqli_connect.php');
include ('./SourceCode/functions.php');
$header_name = 'Trang Chat Chung';
include ('./Includes/Header.php');
include('./Includes/Menu.php');
//Kiểm tra đăng nhập
Is_Login();
//Kiểm tra có biến GET chứa id group chay hay ko, nếu ko có thì là group chat chung
if(isset($_GET['gid']) and filter_var($_GET['gid'],FILTER_VALIDATE_INT)){
    $gid = $_GET['gid'];
    //Truy vấn CSDL lấy danh sách user thuộc group này
    $query = "SELECT `user_id` FROM `connect` WHERE `group_id` = {$gid} AND `user_id` = {$_SESSION['uid']}";
    $result = mysqli_query($dbc, $query);
    if(mysqli_num_rows($result)<=0){        
             Redirect();               
    }
}else{
    Redirect();
}
?>
    <body>
        <div id='chatarea-area'>
            <div id='login-head'>
                Khu vực trò chuyện chung
            </div>
            <div id='chatarea-body'>
               <?php
               include('./Includes/List_User.php');
               ?>
                <div id='chatarea-center'>
                    <div id='chat-center-title'>
                        Phòng chat: 
                        <?php                        
                        //Truy vấn tên phòng chat và phòng chat id
                        $query = "SELECT group_id, group_name FROM `groupchat` WHERE group_id= {$gid}";
                        $result = mysqli_query($dbc, $query);
                        if(mysqli_num_rows($result)==1){
                            while($group = mysqli_fetch_array($result,MYSQLI_ASSOC)){
                               echo "<span class='gname'>".ucfirst($group['group_name'])."</span>";                               
                            }
                        }
                        ?>
                    </div>
                    <div id='chat-center-cbox'>
                        
                    </div>
                    <div id='from-chat'>                        
                        <div id='chat-title'>Nhập nội dung chat:</div>
                        <div name='chatbox'>
                        <div id='chat-mess-box'><input type='text' name='message' size='25' id='chat-mess'></div>
                        <div id='chat-mess-button'><input type='submit' name='chat-submit' id='chat-sent' value='Chat'></div>
                        </div>
                    </div>
                </div><!-- end chatarea-center -->
                <?php
                include('./Includes/Public_Menu.php');
                ?>
            </div>
        </div>
    </body>
</html>
<?php
include('./Includes/Footer.php');